﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using BBS.Entity;

namespace BBS.Data.Forum
{
    public class ThreadTypeTable
    {
        private static string _connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        private BaseTable _table = new BaseTable(_connstr, "Thread_Type_Board_Mapping");

        public DataTable GetAll()
        {
            return _table.SelectTable("where status <> "+(int) StatusType.Delete);
        }

        public int Insert(BBS.Entity.ThreadType type)
        {
            string sql = "insert into Thread_Type_Board_Mapping (title,board_id,last_update_by,last_update_time,status) values(@title,@bid,@lastBy,@lastTime,@status)";
            return _table.ExecuteNonQuery(sql, new OleDbParameter("title", type.Title),
                                                                    new OleDbParameter("bid", type.BoardId),
                                                                    new OleDbParameter("lastBy", type.LastUpdateBy),
                                                                    new OleDbParameter("lastTime", type.LastUpdateTime),
                                                                    new OleDbParameter("status", type.Status));
        }

        public int Update(BBS.Entity.ThreadType type)
        {
            string sql = "update Thread_Type_Board_Mapping set title=@title, board_id=@bid,last_update_by=@lastBy,last_update_time=@lastTime,status=@status where id = @id";
            return _table.ExecuteNonQuery(sql, new OleDbParameter("title", type.Title),
                                                                    new OleDbParameter("bid", type.BoardId),
                                                                    new OleDbParameter("lastBy", type.LastUpdateBy),
                                                                    new OleDbParameter("lastTime", type.LastUpdateTime),
                                                                    new OleDbParameter("status", type.Status),
                                                                    new OleDbParameter("id", type.Id));
        }
    }
}
